# -*- coding: utf-8 -*-
"""
   File Name:  make_dataset.py
   Author :    liccoo
   Time:       2022/8/24 12:34
"""
import math
import random

import numpy as np
import pandas as pd

num_datasize = 1000
_divide_rate = 0.8
_train_dataset_save_path = './dataset/train_dataset.csv'
_test_dataset_save_path = './dataset/test_dataset.csv'

dataset = []
for i in range(num_datasize):
    data_row = []
    x = random.uniform(-1, 1)
    y = math.sin(5 * x) * math.cos(10 * x)
    data_row.append(x)  # 组成 (x,y) 标签对
    data_row.append(y)  # 组成 (x,y) 标签对
    dataset.append(data_row)  # 组成数据集

# 划分数据集
dataset_np = np.array(dataset)
dataset_length = len(dataset_np)
train_dataset_np = dataset_np[0:math.ceil(_divide_rate * dataset_length)]
test_dataset_np = dataset_np[math.ceil(_divide_rate * dataset_length):dataset_length]

# 转换为 DataFrame 格式以便将数据保存为 csv 格式存储
train_dataset_df = pd.DataFrame(train_dataset_np)
test_dataset_df = pd.DataFrame(test_dataset_np)

# 保存为 csv 格式
train_dataset_df.to_csv(_train_dataset_save_path, encoding='utf-8', index=False, header=False)
test_dataset_df.to_csv(_test_dataset_save_path, encoding='utf-8', index=False, header=False)
